package com.shang.core;

import com.shang.core.base.LengthType;
import com.shang.core.base.VariableMeta;

import javax.xml.bind.DatatypeConverter;
import java.nio.charset.StandardCharsets;

/**
 * Created by shangwei2009@hotmail.com on 2021/9/8 10:28
 */
public class DefaultVariableMeta extends VariableMeta {

    public DefaultVariableMeta(String fieldName, Integer metaLength) {
        this(fieldName, metaLength, LengthType.ONE_BYTE);
    }

    public DefaultVariableMeta(String fieldName, Integer metaLength, LengthType lengthType) {
        super(fieldName, metaLength, lengthType);
    }

    @Override
    protected Integer valueLength(String metaStr) {
        // 转数字用ASCII足够
        return Integer.parseInt(new String(DatatypeConverter.parseHexBinary(metaStr), StandardCharsets.US_ASCII));
    }
}
